/**
 * 
 */
package src.model.gameObject.ability;

import src.model.gameObject.GameObjectType;
import src.model.gameObject.PlayerGameObject;
import src.model.gameWorld.ActualMap;
import src.model.gameWorld.Position;

/**
 * <b>Overview</b><br>
 * <p>This allows a PlayerGameObject to carry another friendly unit. When it is called on a unit,
 * it creates an Unload ActiveAbility to hold the unit and allow the player to tell it to unload.</p>
 * <br><br>
 * <b>Responsibilites</b><br>
 * <p>Encapsulate transportation of units. Remove unit from map, and initialize the unload ability.</p>
 * <br><br>
 * <b>Collaborators</b>
 * <br>
 * UnloadUnit - creates this to allow the unit to be stored and unloaded.<br>
 * ActualMap - The map that the unit has to be removed from.<br>
 * <br>
 * <b>Implementor</b> - Tristan Lohman<br>
 * <b>Tester</b> - Tim<br>
 * 
 * @author Tristan
 *
 */
public class LoadUnit extends ActiveAbility {

	private ActualMap am;
	/**
	 * @param pgo
	 * @param am
	 */
	public LoadUnit(PlayerGameObject pgo, ActualMap am) {
		super(pgo, AbilityType.LOADUNIT, null);
		this.am = am;
	}
	
	public AbilityReturnResult execute(Position... position){
		PlayerGameObject friendly = (PlayerGameObject)am.findObject(position[0], GameObjectType.UNIT);
		if (friendly == null) return AbilityReturnResult.IMPOSSIBLE;
		if (friendly.player() != super.gameObject().player()) return AbilityReturnResult.IMPOSSIBLE;
		am.removeObject(friendly);
		UnloadUnit unloader = new UnloadUnit(super.gameObject(), friendly, super.playerLookupTable(), am, this);
		PlayerGameObject owner = super.gameObject();
		owner.removeActiveAbility(this);
		owner.addActiveAbility(unloader);
		return AbilityReturnResult.SUCCESS;
	}	
	
	public boolean queueToMission(Position...position){
		if (position.length == 0)  return false;
		super.gameObject().enqueueAbility(this, position);
		return true;
	}

	public void destroySub(){
		// TODO: IMPLEMENT!!!!
	}
}
